//
//  RootViewController.m
//  SweetComics
//
//  Created by LeeZhe on 15/1/28.
//  Copyright (c) 2015年 LeeZhe. All rights reserved.
//

#import "RootViewController.h"
#import "UserViewController.h"
#import "TakeViewController.h"
#import "ClassifyViewController.h"
#import "HomePageViewController.h"
#import "ReCommendViewController.h"
#import "Reachability.h"
@interface RootViewController ()<UIAlertViewDelegate>
- (void)createViewController;
@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor grayColor];
    
        [self createViewController];
    
}

- (BOOL)reachAbility
{
    Reachability *r = [Reachability reachabilityForInternetConnection];
    if (r.currentReachabilityStatus ==  0) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"没有网络连接\r甜心偷懒拉" delegate: self cancelButtonTitle:@"联网重试" otherButtonTitles:@"好的",nil];
        [alertView show];
        [self.view addSubview:alertView];
        [alertView release];
        return NO;
    }
    return YES;
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        if ([self reachAbility]) {
            [self createViewController];
        }
    }else{
        
    }
}

- (void)createViewController
{
    // 首页
    
    HomePageViewController *homeVC = [[[HomePageViewController alloc] init] autorelease];
    
    UINavigationController *homeNC = [[[UINavigationController alloc] initWithRootViewController:homeVC] autorelease];
    
    homeNC.tabBarItem.title = @"首页";
    homeNC.tabBarItem.image = [UIImage imageNamed:@"iconfont-shouye.png"];
    
    // 推荐
    
    ReCommendViewController *recommendVC = [[[ReCommendViewController alloc] init] autorelease];
    
    UINavigationController *recommendNC = [[[UINavigationController alloc] initWithRootViewController:recommendVC] autorelease] ;
    recommendNC.tabBarItem.title = @"推荐";
    recommendNC.tabBarItem.image = [UIImage imageNamed:@"iconfont-tuijian.png"];
    
    
    
    // 用户
    UserViewController *userVC = [[[UserViewController alloc] init] autorelease];
    UINavigationController *userNC = [[[UINavigationController alloc] initWithRootViewController:userVC] autorelease];
    userNC.tabBarItem.title = @"用户";
    userNC.tabBarItem.image = [UIImage imageNamed:@"iconfont-yonghu.png"];
    
    // 订阅
    TakeViewController  *takeVC = [[[TakeViewController alloc] init] autorelease];
    UINavigationController *takeNC = [[[UINavigationController alloc] initWithRootViewController:takeVC] autorelease];
    takeNC.tabBarItem.title = @"订阅";
    takeNC.tabBarItem.image = [UIImage imageNamed:@"iconfont-shoucangyuankongxin.png"];
    
    self.viewControllers = @[homeNC,recommendNC,takeNC,userNC];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
